from GameController import GameController
from Player import Player

def printMenu():
	print """
	Welcome to Elite TicTacToe!
	Please select from menu:
	1. PlayerVsPlayer
	2. PlayerVsComputer
	3. Quit
	"""

def run():
	while 1:
		try:
			player1 = None
			player2 = None
			
			printMenu()
			try:
				menuSelection = int(raw_input(" >> "))
				
				if menuSelection not in [1, 2, 3]:
					raise ValueError
					
			except ValueError:
				print "Not a valid selection"
				continue
			
			if menuSelection == 1:
				player1Name = str(raw_input("Player1 name: "))
				player2Name = str(raw_input("Player2 name: "))
				
				player1 = Player('X', player1Name)
				player2 = Player('O', player2Name)
				
			elif menuSelection == 2:
				player1Name = str(raw_input("Player1 name: "))
				
				player1 = Player('X', player1Name)
				player2 = None
				
			else:
				break
			
			controller = GameController(player1, player2)
			
			controller.newGame()

		except KeyboardInterrupt, ValueError:
			print "Exiting gracefully!"
			break
		except Exception as e:
			print "Unexpected error occured, exiting gracefully"
			print e
			break

if __name__ == '__main__':
	run()